package com.csyaonie.android;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.csyaonie.android.utils.ToastUtil;

public class PopupWindowActivity extends AppCompatActivity {

    private Button popbt;

    private PopupWindow pw;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popup_window);

        popbt=findViewById(R.id.popbt);
        popbt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                View view= getLayoutInflater().inflate(R.layout.popup_window_layout,null);
                TextView textView=view.findViewById(R.id.popup_tv1);

                pw=new PopupWindow(view,popbt.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT);
                pw.showAsDropDown(popbt);
                pw.setOutsideTouchable(true);


                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pw.dismiss();
                        ToastUtil.show(PopupWindowActivity.this,"good");
                    }
                });

            }
        });

    }
}